package top.xshiwu.demo.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import top.xshiwu.demo.service.impl.MailServiceImpl;

import javax.annotation.Resource;
import javax.mail.MessagingException;

@Component
public class Scheduler1Task {
    private Logger logger = LoggerFactory.getLogger(Scheduler1Task.class);
    private int count = 1;

    /**
     * 要发送邮件的QQ
     */
    @Value("${to.qq}")
    String[] to = {};

    /**
     * 邮件标题
     */
    @Value("${to.title}")
    String title;

    /**
     * 邮件内容
     */
    @Value("${to.content}")
    String content;

    String filename = "健康打卡";

    String images = "F:\\项目开发\\maill\\src\\main\\resources\\static\\g.jpg";

    @Resource
    private MailServiceImpl mailService;

    // 每天的10:30:10发送邮件
    @Scheduled(cron = "15 02 13 * * ?")
    private void proces() throws MessagingException {

        // String[] to = {"507131158@qq.com"};
        logger.info("开始发送邮件，次数:" + (count++) + "次");
        mailService.sendMail(to, title, content);
        logger.info("邮件发送成功！");
    }
    @Scheduled(cron = "15 13 15 * * ?")
    private void procesImages() {
        logger.info("开始发送邮件，次数:" + (count++) + "次");
        mailService.sendMail(new String[]{"2385756401@qq.com"},"健康打卡", "内容区域",images);
        logger.info("邮件发送成功！");
    }

    @Scheduled(cron = "15 17 17 * * ?")
    private void procesImage(){
        mailService.sendMail(to, "helloWorld", "<h1 style='color:red;width:1250px;height:700px'>helloWorld</h1><img src='cid:test001'/>",images,"test001");
    }
}
